package com.dsf.lembda.test.Lambda;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

/**
 * @Author: Dgg
 * @Date: 2021/3/16 20:35
 * Stream api
 */
public class LambdaDemo2 {
	public static void main(String[] args) {
		/*
		Stream API代替for循环
		List<String> nameStrs = Arrays.asList("Monkey", "Lion", "Giraffe","Lemur");
		List<String> list = nameStrs.stream()
				.filter(s -> s.startsWith("L"))
				.map(String::toUpperCase)
				.sorted()
				.collect(toList());*/
		//将数组转换为管道流
		/*String[] array = {"Monkey", "Lion", "Giraffe", "Lemur"};
		Stream<String> nameStrs2 = Stream.of(array);
		Stream<String> nameStrs3 = Stream.of("Monkey", "Lion", "Giraffe", "Lemur");*/
		//将集合类对象转换为管道流
		List<String> list = Arrays.asList("Monkey", "Lion", "Giraffe", "Lemur");
		Stream<String> streamFromList = list.stream();
		List<String> list1 = streamFromList.filter(s -> s.startsWith("M"))
				.map(String::toUpperCase)
				.sorted()
				.collect(toList());
		Set<String> set = new HashSet<>(list);
		Stream<String> streamFromSet = set.stream();
		System.out.println("list1:" + list1.get(0));
	}
}
